<?php
session_start();
require 'connection.php';
require 'util.php';
$pks = $_SESSION['listedResults'];
$id = substr($_POST['id'], -10);
if(isset($id) && $pks[$id] != ""){
	$pk = $pks[$id];
	//print_r(getListingAndUserInfo($pk)[0]);
	showListingInfo(getListingAndUserInfo($pk)[0]);
	//echo "<div><p>ñañañaña</p></div>";
}else{
	echo "Error while retrieving the info.";
}

function getListingAndUserInfo($listingId){
	$ini = parse_ini_file("ini/queries.ini", true);
	$query = $ini['listings']['listingsFromId'];
	$params = array(
		":resultpk"=>$listingId
		);
	return getResultArray($query, $GLOBALS['pdo'], $params);
	//return "a";
}

function showListingInfo($listing){
	//print_r($listing);
	?>

	<div id="moreInfoContainer">
		<div id="listingInfo">
			<div id="LIImage">
				<img src="<?php echo $listing['image_url']; ?>">
			</div>
			<div id="LIContents">
				<div id="LITitle">
					<h2><?php echo $listing['title']; ?></h2>
					<h2><?php echo $listing['price']; ?></h2>
				</div>
				<div id="LIDescription">

					<div id="LIAddress">
						<h3><?php echo $listing['city'].", ".$listing['district'].", ".$listing['street']."."; ?></h3>
					</div>

					<div id="LIDescription">
						<?php
							displayTextIfExists($listing['description'], "Description");
							displayTextIfExists($listing['week_price'], "Week Price");
							displayTextIfExists($listing['month_price'], "Month Price");
							displayTextIfExists($listing['rules'], "Rules");
							displayTextIfExists($listing['accomodates'], "Accomodates");
							displayTextIfExists($listing['bedrooms'], "Bedrooms");
							displayTextIfExists($listing['beds'], "Beds");
							displayTextIfExists($listing['cancellation_type'], "Cancellation");
							displayTextIfExists($listing['cancellation_fee'], "Cancellation Fee");
							displayTextIfExists($listing['webpage'], "Webpage");
						?>

					</div>
				</div>
			</div>
			<a href="#">Show contact info</a>
		</div>
		<div id="userInfo">
			<div id="UIImageContainer">
				<?php
					displayImage(emptyString($listing['first_user_image']) ? (emptyString($listing['second_user_image']) ? $GLOBALS['noPicImgUrl'] : $listing['second_user_image']) : $listing['first_user_image']);
				?>
			</div>
			<div id="UIInfo">
			<?php
			displayTextIfExists($listing['user_id'], "User");
			displayTextIfExists($listing['first_name']." ".$listing['first_lastname'], "Name: ");
			?>
			</div>
		</div>
		
	</div>
	<?php

}
function showUserInfo($listing){

}


?>
